﻿using Crap4Net;
using System;
using NUnit.Framework;
namespace Crap4Net.UnitTests
{
    [TestFixture]
    public class CrapCalculatorTest
    {

        [Test]
        public void CalculateCrap_LegalValues_ReturnCorrectCrap()
        {
            //arrange
            var CCValue = 15;
            var CoverageValue = 65; //%

            //act
            var actual = CrapCalculator.CalculateCrap(CCValue, CoverageValue);

            //assert
            Assert.AreEqual(24.65d, actual);
        }

        [Test]
        public void CalculateCrap_LegalValues_ReturnCorrectCrap2()
        {
            var CCValue = 10;
            var CoverageValue = 30; 


            var actual = CrapCalculator.CalculateCrap(CCValue, CoverageValue);

            Assert.AreEqual(44.3d, actual);
            
        }

        [Test]
        public void CalculateCrap_LegalValues_ReturnCorrectCrap3()
        {
            var CCValue = 2;
            var CoverageValue = 66;

            var actual = CrapCalculator.CalculateCrap(CCValue, CoverageValue);

            Assert.AreEqual(2.16d, actual);

        }


        [Test]
        public void CalculateCrap_NegativeCoverageData_ThrowsException()
        {
            var ccValue = 5;
            var covarageValue = -1;

            Assert.Throws<ArgumentException>(()=>CrapCalculator.CalculateCrap(ccValue, covarageValue));
        }

        [Test]
        public void CalculateCrap_CoverageBiggerThen100_ThrowsExceptionSpecificSyntax()
        {
            var ccValue = 5;
            var covarageValue = 150;
            var ex = Assert.Throws<ArgumentException>(() => CrapCalculator.CalculateCrap(ccValue, covarageValue));
            Assert.That(ex.Message,Is.StringContaining("Illegal Coverage Value"));
            Assert.That(ex.Message, Is.StringContaining(covarageValue.ToString()));
        }

        [Test]
        public void CalculateCrap_NegativeCCValue_ThrowsException()
        {
            var ccValue = -5;
            var covarageValue = 20;
            var ex = Assert.Throws<ArgumentException>(() => CrapCalculator.CalculateCrap(ccValue, covarageValue));
            Assert.AreEqual("CCValue cant be negative",ex.Message);
        }
    }
}
